package cn.wolfcode.rbac.controller;

import cn.wolfcode.rbac.domain.Permission;
import cn.wolfcode.rbac.qo.PermissionQo;
import cn.wolfcode.rbac.service.PermissionService;
import cn.wolfcode.rbac.util.RequiredPermission;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

/**
 * @author xiahuihui
 * #Description PermissionController
 * #Date: 2022/7/2 13:45
 */
@Controller
@RequestMapping("/permission")
public class PermissionController {

    @Autowired
    private PermissionService permissionService;

    //查询权限
    @RequestMapping("/list")
    @RequiredPermission({"权限列表","permission:list"})
    public String findPermissionALl(Model model, PermissionQo qo){
        //List<Permission> permissionAll = permissionService.findPermissionAll();
        //分页查询
        PageInfo<Permission> pageResult = permissionService.findByPage(qo);
        model.addAttribute("pageResult",pageResult);
        return "permission/list";
    }

    //重新加载权限
    @RequestMapping("/reload")
    public String reload(){
       permissionService.reload();
        return "redirect:/permission/list";
    }

    //删除权限
    @RequestMapping("/delete")
    @RequiredPermission({"权限删除","permission:delete"})
    public String deletePermission(Long id){
        permissionService.deletePermission(id);
        return "redirect:list";
    }
}
